import type { PageResult } from '#/type/base_beans';
import type { SysDeptReq, SysDeptResp } from '#/type/sys_dept';

import { requestClient } from '#/api/request';

const API_PREFIX = '/sys/dept';

/**
 * 获取登录用户信息
 */
export async function getDeptAndChildesByIdApi(deptId: string = '0') {
  return requestClient.get<Array<SysDeptResp>>(
    `${API_PREFIX}/get_with_childes_by_id`,
    { params: { deptId } },
  );
}

export async function getDeptByIdApi(id: string) {
  return requestClient.get<SysDeptResp>(`${API_PREFIX}/get_by_id/${id}`);
}

export async function getDeptListByIdsApi(ids: Array<string>) {
  return requestClient.get<Array<SysDeptResp>>(`${API_PREFIX}/get_by_ids`, {
    params: { ids },
  });
}

export async function getDeptListApi(params: SysDeptReq) {
  return requestClient.get<Array<SysDeptResp>>(`${API_PREFIX}/list`, {
    params,
  });
}

export async function getDeptPageApi(params: SysDeptReq) {
  return requestClient.get<PageResult<SysDeptResp>>(`${API_PREFIX}/page`, {
    params,
  });
}

export async function createDeptApi(data: SysDeptReq) {
  return requestClient.post<Promise<void>>(`${API_PREFIX}/create`, data);
}

export async function editDeptApi(data: SysDeptReq) {
  return requestClient.put<Promise<void>>(`${API_PREFIX}/edit`, data);
}

export async function createEditDeptApi(data: SysDeptReq) {
  return requestClient.post<Promise<void>>(`${API_PREFIX}/create_edit`, data);
}

export async function deleteDeptApi(ids: Array<string>) {
  return requestClient.delete<Promise<void>>(`${API_PREFIX}/delete`, {
    params: { ids },
  });
}
